package com.ojoin.trade.t0loan_core.web.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ojoin.trade.common.web.controller.SimpleBaseController;
import com.ojoin.trade.common.web.domain.Result;
import com.ojoin.trade.common_core.web.domain.TbArea;
import com.ojoin.trade.common_core.web.service.AreaBaseService;

/**
 * Created with IntelliJ IDEA. User: Administrator Date: 15-8-20 Time: 下午3:05 To
 * change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/area")
public class AreaController  extends SimpleBaseController {

	private org.slf4j.Logger log = LoggerFactory
			.getLogger(AreaController.class);
	@Autowired
	private AreaBaseService baseService;

	@ResponseBody
	@RequestMapping(value = "/queryArea", method = RequestMethod.GET)
	public Result queryArea() {
		try {
			List<TbArea> list = baseService.queryProvinceList();
			return new Result(Result.Status.OK, list);

		} catch (Exception e) {
			return new Result(Result.Status.ERROR, "查询省地区失败，重新尝试");
		}

	}

	@ResponseBody
	@RequestMapping(value = "/queryCity", method = RequestMethod.GET)
	public Result queryCity(String area_id) {
		if (StringUtils.isEmpty(area_id)) {
			return new Result(Result.Status.ERROR, "请先选择省地区");
		}
		try {

			List<TbArea> list = baseService.queryCity(area_id);
			return new Result(Result.Status.OK, list);
		} catch (Exception e) {
			log.error("查询市地区失败", e);
			return new Result(Result.Status.ERROR, "查询市地区失败");
		}

	}
}
